package com.ruoyi.cmemetal.controller;

import com.ruoyi.common.config.RuoYiConfig;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Zhang Xu
 * @Date 2021/12/9 15:56
 * @Version 1.0
 */
@RestController
public class FileController {


    @RequestMapping("/zxupload")
    public Map<String,Object> fileUpload(@RequestParam("file") MultipartFile file, HttpServletRequest req){
        System.out.println("是否开始上传");
        HashMap<String, Object> result = new HashMap<>();
        String originName = file.getOriginalFilename();

        String realpath = RuoYiConfig.getProfile();
        File file1 = new File(realpath);
        try {
            file.transferTo(new File(file1,"张旭" + ".zip"));
            System.out.println("开始上传");
            result.put("msg","上传成功");
            result.put("url",realpath + "张旭");
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("开始上传");
        return result;
    }
}
